#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.59)
AC_INIT([fractacular], [0.2], [fractacular@gmail.com])
AM_INIT_AUTOMAKE([fractacular], [0.2])
AC_CONFIG_HEADER([config.h])
AC_CONFIG_MACRO_DIR([m4])

# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_RANLIB
AC_CHECK_TOOL(PACKAGE_CONFIG, pkg-config)

# Checks for libraries.

##########################################################################
# check for libboost
##########################################################################
AX_BOOST_BASE([1.32.00])
if test "$succeeded" != "yes" ; then
	AC_MSG_NOTICE([])
	AC_MSG_ERROR([*** libboost not found])
else
	AM_CXXFLAGS="$AM_CXXFLAGS $BOOST_CPPFLAGS"
	AM_LDFLAGS="$AM_LDFLAGS $BOOST_LDFLAGS"
fi
AX_BOOST_PROGRAM_OPTIONS

##########################################################################
# check for libpng
##########################################################################
AC_ARG_WITH(libpng, [  --with-libpng=PREFIX        Specify the libpng installation path], LIBPNG_DIR=$withval)
AC_MSG_CHECKING(for libpng)
LIBPNG=$LIBPNG_DIR/lib/libpng.a
if test -e "$LIBPNG"; then
 	AM_CXXFLAGS="$AM_CXXFLAGS -I$LIBPNG_DIR/include"
	AC_SUBST([LIBPNG])
	AC_MSG_RESULT($LIBPNG)
else
	echo ""
	AC_MSG_ERROR([*** libpng not found (prefix=$LIBPNG_DIR)])
fi

##########################################################################
# check for libmicrohttpd
##########################################################################
#AC_ARG_WITH(libmicrohttpd, [  --with-libmicrohttpd=PREFIX        Specify the libmicrohttpd installation path], LIBMICROHTTPD_DIR=$withval)
#AC_MSG_CHECKING(for libmicrohttpd)
#LIBMICROHTTPD=$LIBMICROHTTPD_DIR/lib/libmicrohttpd.a
#if test -e "$LIBMICROHTTPD"; then
# 	AM_CXXFLAGS="$AM_CXXFLAGS -I$LIBMICROHTTPD_DIR/include"
#	AC_SUBST([LIBMICROHTTPD])
#	AC_MSG_RESULT($LIBMICROHTTPD)
#else
#	echo ""
#	AC_MSG_ERROR([*** libmicrohttpd not found (prefix=$LIBMICROHTTPD_DIR)])
#fi

##########################################################################
# check for MW
##########################################################################
AC_ARG_WITH(MW, [  --with-MW=PREFIX        Specify the MW installation path], MW_DIR=$withval)
AC_MSG_CHECKING(for libMW)
if test -e "$MW_DIR/lib/libMW.a"; then
    LIB_CFLAGS="-I$MW_DIR/include"
    LIB_LDFLAGS="-L$MW_DIR/lib"
    AM_CXXFLAGS="$AM_CXXFLAGS $LIB_CFLAGS"
    AM_LDFLAGS="$AM_LDFLAGS $LIB_LDFLAGS"
	AC_MSG_RESULT($MW_DIR)
else
    AC_MSG_NOTICE([])
	AC_MSG_ERROR([*** libMW not found])
	exit 1
fi

# Checks for header files.
AC_HEADER_STDC

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.
AC_CHECK_FUNCS([sqrt])

# debug
AC_MSG_CHECKING([whether to build with debug information])
AC_ARG_ENABLE([debug],
    [AS_HELP_STRING([--enable-debug],
        [disable debug data generation (def=no)])],
    [debugit="$enableval"],
    [debugit=no])
AC_MSG_RESULT([$debugit])

if test x"$debugit" = x"yes"; then
    AC_DEFINE([DEBUG],[],[Debug Mode])
    AM_CXXFLAGS="$AM_CXXFLAGS -g -Wall -Werror -Wno-uninitialized -O0"
else
    AC_DEFINE([NDEBUG],[],[No-debug Mode])
    AM_CXXFLAGS="$AM_CXXFLAGS -O3"
fi

# distribute additional compiler and linker flags
AC_SUBST([AM_CXXFLAGS])
AC_SUBST([AM_LDFLAGS])

AC_OUTPUT([
	Makefile
	src/Makefile
	src/condor-mw/Makefile
	src/libfractal/Makefile
])